function  graphs_friendships_formation(data_baseline,param_est,fp)

distrib_log_skills_grade10 = [];

for h = 1:fp.n_rip_sim
for j = 1:4
    
    distrib_log_skills_grade10 = [distrib_log_skills_grade10 ;  log(data_baseline{j}(  data_baseline{j}(:,fp.ind_data.child_age , h )==10, fp.ind_data.child_C , h ))    ];
    
end
end


p_skills(1) = prctile(distrib_log_skills_grade10,10);
p_skills(2) = prctile(distrib_log_skills_grade10,90);

gamma = param_est(15:19)./100;

Prob_friendship_i_j = cell(2,2);

for PS1 = 0:1
for PS2 = 0:1

for p1 = 10:10:90

    log_H1 =  prctile(distrib_log_skills_grade10,p1);
    
for p2 = 1:1:2

    log_H2 = p_skills(p2);
    
    
    U_links1 = gamma(1)  +  ...
               gamma(2).*log_H1 + gamma(3).*log_H2 + gamma(4).*(log_H1 - log_H2).^(2) + ...
               gamma(5).*( (log_H1 - log_H2).^(2) ).*(log_H1 - log_H2>0).*PS1;                                                 
       
    U_links2 = gamma(1)  +  ...
               gamma(2).*log_H2 + gamma(3).*log_H1 + gamma(4).*(log_H1 - log_H2).^(2) + ...
               gamma(5).*( (log_H1 - log_H2).^(2) ).*(log_H2 - log_H1>0).*PS2;         

    Prob_friendship_i_j{PS1+1,PS2+1}(p1/10,p2) = (1./(1+1./exp(U_links1))).*(1./(1+1./exp(U_links2))) ;       

end
end

end
end



% 1. Graph PS1=0 & PS2=0  
cd(fp.paper)    
h1=figure;
plot(10:10:90,Prob_friendship_i_j{1,1}(:,1),'--ro','LineWidth',3.5,...
                       'MarkerEdgeColor','r',...
                       'MarkerFaceColor','r',...
                       'MarkerSize',7.5)
hold on
plot(10:10:90,Prob_friendship_i_j{1,1}(:,2),'--bo','LineWidth',3.5,...
                       'MarkerEdgeColor','b',...
                       'MarkerFaceColor','b',...
                       'MarkerSize',7.5)                   
legend('Child j (10th Percentile)', 'Child j (90th Percentile)' ) 
xlabel('Child i`s Skill Percentile');
ylabel('Probability of Friendship');
axis([10 90 0 0.07])
hold off

hgexport(h1, 'Prob_Friends_00.png',hgexport('factorystyle'), 'Format', 'png');
hgexport(h1, 'Prob_Friends_00.eps',hgexport('factorystyle'), 'Format', 'eps'); 




h2=figure;
plot(10:10:90,Prob_friendship_i_j{2,2}(:,1),'--ro','LineWidth',3.5,...
                       'MarkerEdgeColor','r',...
                       'MarkerFaceColor','r',...
                       'MarkerSize',7.5)
hold on
plot(10:10:90,Prob_friendship_i_j{2,2}(:,2),'--bo','LineWidth',3.5,...
                       'MarkerEdgeColor','b',...
                       'MarkerFaceColor','b',...
                       'MarkerSize',7.5)                 
legend('Child j (10th Percentile)', 'Child j (90th Percentile)' ) 
xlabel('Child i`s Skill Percentile');
ylabel('Probability of Friendship');
axis([10 90 0 0.07])
hold off

hgexport(h2, 'Prob_Friends_11.png',hgexport('factorystyle'), 'Format', 'png');
hgexport(h2, 'Prob_Friends_11.eps',hgexport('factorystyle'), 'Format', 'eps'); 


h3=figure;
plot(10:10:90,Prob_friendship_i_j{1,2}(:,1),'--ro','LineWidth',3.5,...
'MarkerEdgeColor','r',...
'MarkerFaceColor','r',...
'MarkerSize',7.5)
hold on
plot(10:10:90,Prob_friendship_i_j{1,2}(:,2),'--bo','LineWidth',3.5,...
'MarkerEdgeColor','b',...
'MarkerFaceColor','b',...
'MarkerSize',7.5)
legend('Child j (10th Percentile)', 'Child j (90th Percentile)' ) 
xlabel('Child i`s Skill Percentile');
ylabel('Probability of Friendship');
axis([10 90 0 0.07])
hold off
hgexport(h3, 'Prob_Friends_01.png',hgexport('factorystyle'), 'Format', 'png');
hgexport(h3, 'Prob_Friends_01.eps',hgexport('factorystyle'), 'Format', 'eps'); 

h4=figure;
plot(10:10:90,Prob_friendship_i_j{2,1}(:,1),'--ro','LineWidth',3.5,...
'MarkerEdgeColor','r',...
'MarkerFaceColor','r',...
'MarkerSize',7.5)
hold on
plot(10:10:90,Prob_friendship_i_j{2,1}(:,2),'--bo','LineWidth',3.5,...
'MarkerEdgeColor','b',...
'MarkerFaceColor','b',...
'MarkerSize',7.5)
legend('Child j (10th Percentile)', 'Child j (90th Percentile)' ) 
xlabel('Child i`s Skill Percentile');
ylabel('Probability of Friendship');
axis([10 90 0 0.07])
hold off
hgexport(h4, 'Prob_Friends_10.png',hgexport('factorystyle'), 'Format', 'png');
hgexport(h4, 'Prob_Friends_10.eps',hgexport('factorystyle'), 'Format', 'eps'); 

cd(fp.matlab)

end